package demo6;

import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86183
 */
public class Test {
    public static void mySort(Comparable[] comparables){
        for (int i = 0; i < comparables.length -1; i++) {
            for (int j = 0; j < comparables.length - 1 - i ; j++) {
                if (comparables[j].compareTo(comparables[j + 1]) > 0){//
                    Comparable tmp = comparables[j];
                    comparables[j] = comparables[j + 1];
                    comparables[j + 1] = tmp;
                }
            }

        }
    }

    public static void main(String[] args) {
        Student[] student = new Student[3];
        student[0] = new Student("小贺",20);
        student[1] = new Student("小马",22);
        student[2] = new Student("小张",21);
        System.out.println("排序前："+ Arrays.toString(student));
        mySort(student);

        System.out.println("排序后："+ Arrays.toString(student));
    }
    public static void main2(String[] args) {
        Student[] student = new Student[3];
        student[0] = new Student("小贺",20);
        student[1] = new Student("小马",22);
        student[2] = new Student("小张",21);
        System.out.println("排序前："+ Arrays.toString(student));
        Arrays.sort(student);

        System.out.println("排序后："+ Arrays.toString(student));
    }
    public static void main1(String[] args) {
        Student[] student = new Student[3];
        student[0] = new Student("小贺",20);
        student[1] = new Student("小马",22);
        student[2] = new Student("小张",21);
        System.out.println("排序前："+ Arrays.toString(student));
        Arrays.sort(student);//报异常
        System.out.println("排序后："+ Arrays.toString(student));
    }
}
